package com.library.web.controller.library;


import com.library.common.annotation.Log;
import com.library.common.core.controller.BaseController;
import com.library.common.core.domain.AjaxResult;
import com.library.common.core.page.TableDataInfo;
import com.library.common.enums.BusinessType;
import com.library.common.utils.poi.ExcelUtil;
import com.library.domain.MbGoodsType;
import com.library.service.IMbGoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 商品分类 信息操作处理
 *
 * @author null
 * @date 2020-04-23
 */
@RestController
@RequestMapping("/library/mbGoodsType")
public class MbGoodsTypeController extends BaseController {
    private String prefix = "business/mobile/mbGoodsType";

    @Autowired
    private IMbGoodsTypeService mbGoodsTypeService;

    /**
     * 查询商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('library:mbGoodsType:list')")
    @GetMapping("/list")
    public TableDataInfo list(MbGoodsType mbGoodsType) {
        startPage();
        List<MbGoodsType> list = mbGoodsTypeService.selectMbGoodsTypeList(mbGoodsType);
        return getDataTable(list);
    }

    /**
     * 导出商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('library:mbGoodsType:export')")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MbGoodsType mbGoodsType) {
        List<MbGoodsType> list = mbGoodsTypeService.selectMbGoodsTypeList(mbGoodsType);
        ExcelUtil<MbGoodsType> util = new ExcelUtil<MbGoodsType>(MbGoodsType.class);
        util.exportExcel(response, list, "商品分类数据");
    }

    /**
     * 获取商品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('library:mbGoodsType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(mbGoodsTypeService.selectMbGoodsTypeById(id));
    }

    /**
     * 新增商品分类
     */
    @PreAuthorize("@ss.hasPermi('library:mbGoodsType:add')")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MbGoodsType mbGoodsType) {
        return toAjax(mbGoodsTypeService.insertMbGoodsType(mbGoodsType));
    }

    /**
     * 修改商品分类
     */
    @PreAuthorize("@ss.hasPermi('library:mbGoodsType:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MbGoodsType mbGoodsType) {
        return toAjax(mbGoodsTypeService.updateMbGoodsType(mbGoodsType));
    }

    /**
     * 删除商品分类
     */
    @PreAuthorize("@ss.hasPermi('library:mbGoodsType:remove')")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mbGoodsTypeService.deleteMbGoodsTypeByIds(ids));
    }

}
